/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-09 21:37:49
 * @LastEditTime: 2019-10-06 15:09:12
 * @LastEditors: Please set LastEditors
 */
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

const router = new Router({
    mode: 'history',
    // routes: [{ //我的投稿    
    //     path: '/write',
    //     name: 'Write',
    //     component: resolve => require(['../components/mo/article/writeArticle/writeArticle.vue'], resolve),
    //     meta: {
    //         requireAuth: true
    //     }
    // }, { //个人资料
    //     path: '/userinfo',
    //     name: 'Userinfo',
    //     component: resolve => require(['../components/mo/userinfo/userinfo.vue'], resolve),
    //     redirect: '/userinfoJb',
    //     children: [{
    //         path: '/userinfoGz',
    //         name: 'UserinfoGz',
    //         component: resolve => require(['../components/mo/userinfo/userinfoGz/userinfoGz.vue'], resolve),
    //     }, {
    //         path: '/userinfoSc',
    //         name: 'UserinfoSc',
    //         component: resolve => require(['../components/mo/userinfo/userinfoSc/userinfoSc.vue'], resolve),
    //     }, {
    //         path: '/userinfoJb',
    //         name: 'UserinfoJb',
    //         component: resolve => require(['../components/mo/userinfo/userinfoJb/userinfoJb.vue'], resolve),
    //     }, {
    //         path: '/userinfoFs',
    //         name: 'UserinfoFs',
    //         component: resolve => require(['../components/mo/userinfo/userinfoFs/userinfoFs.vue'], resolve),
    //     }]
    // }]
})

// 判断是否需要登录权限 以及是否登录
router.beforeEach((to, from, next) => {
    sessionStorage.setItem('route', to.path)
    if (to.matched.some(res => res.meta.requireAuth)) { // 判断是否需要登录权限
        if (localStorage.getItem("loginfo1") == 'true') { // 判断是否登录
            next()
        } else { // 没登录则跳转到登录界面
            next({
                path: '/login',
                query: {
                    redirect: to.fullPath
                }
            })
        }
    } else {
        next()
    }
})

export default router